package com.quanquan.service.impl;

import com.quanquan.entity.LessonInfo;
import com.quanquan.repository.LessonInfoRepository;
import com.quanquan.service.LessonInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class LessonInfoServiceImpl implements LessonInfoService {

    @Autowired
    private LessonInfoRepository lessonInfoRepository;

    @Override
    public void save(LessonInfo lessonInfo) {
        lessonInfoRepository.save(lessonInfo);
    }

//    @Override
//    public List<LessonInfo> findByGrade(String grade, Pageable pageable) {
//        return lessonInfoRepository.findByGrade(grade);
//    }

    @Override
    public LessonInfo findById(Long id){
        return lessonInfoRepository.findById(id);
    }

    @Override
    public List<LessonInfo> findByLessonNameContaining(String lessonName) {
        return lessonInfoRepository.findByLessonNameContaining(lessonName);
    }

    public List<LessonInfo> findLesson(String grade,Long id) {
        return lessonInfoRepository.findLesson(grade,id);
    }

    public Page<LessonInfo> findAll(Pageable pageable) {
        return lessonInfoRepository.findAll(pageable);
    }

    public Long countLesson(String grade) {
        return lessonInfoRepository.countLesson(grade);
    }


    public Page<LessonInfo> findPageData(Specification<LessonInfo> specification,
                                      Pageable pageable) {
        // TODO Auto-generated method stub
        return lessonInfoRepository.findAll(specification,pageable);
    }

    public Page<LessonInfo> findByGradeLike(String grade, Pageable pageable) {
        return lessonInfoRepository.findAllByGradeLike(grade, pageable);
    }

    public List<LessonInfo> findKeywords(String keywords) {
        return lessonInfoRepository.findKeywords(keywords);
    }

    public List<LessonInfo> findAll() {
        return lessonInfoRepository.findAll();
    }
}


